package com.kunyi.web.service.log.mapper;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kunyi.web.service.log.entity.domain.LogOps;
import com.kunyi.web.service.log.entity.req.LogOpsListReq;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * @ClassName LogOpsMapper
 * @Description log_ops表
 * @Author pengjunjun
 * @Date 2024/3/6 14:26
 * @Version 1.0
 **/
@Repository
public interface LogOpsMapper extends BaseMapper<LogOps> {
    /**
     * @Author pengjunjun
     * @Description 查询log_ops列表
     * @Date 16:22 2024/3/6
     * @Param req:
     * @return List<LogOps>
     **/
    default List<LogOps> listByReq(LogOpsListReq req) {
        LambdaQueryWrapper<LogOps> wrapper = Wrappers.lambdaQuery(LogOps.class)
                .eq(StrUtil.isNotBlank(req.getCode()), LogOps::getCode, req.getCode())
                .like(StrUtil.isNotBlank(req.getCreateUser()), LogOps::getCreateUser, req.getCreateUser())
                .eq(StrUtil.isNotBlank(req.getIp()), LogOps::getIp, req.getIp())
                .eq(StrUtil.isNotBlank(req.getOpsObject()), LogOps::getOpsObject, req.getOpsObject())
                .eq(Objects.nonNull(req.getOpsType()), LogOps::getOpsType, req.getOpsType())
                .eq(Objects.nonNull(req.getStatus()), LogOps::getStatus, req.getStatus())
                .orderByDesc(LogOps::getCreateTime);
        return selectList(wrapper);

    }
}
